package com.hujesse.controller;

import com.google.gson.Gson;
import com.hujesse.pojo.User;
import com.hujesse.service.user.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@CrossOrigin
public class LoginController {
    @Autowired
    private UserServiceImpl userService;

    @RequestMapping("/login")
    public String login(@RequestBody User user){
        Map<String, Object> userByInfo = userService.queryUserByInfo(user.getUsername(), user.getPassword());
        Gson gson = new Gson();
        String userInfo = gson.toJson(userByInfo);
        return userInfo;
        // 可以返回map，但string好看一点，或者说是一种规范
        /*return userByInfo;*/
    }
}
